package com.sap.sap_mangers.handler;

import com.alibaba.fastjson.JSON;
import com.sap.sap_mangers.until.SimpleJson;
import com.sap.sap_mangers.until.WebUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ADong
 * @Date 2022年7月6日 11点59分
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        SimpleJson result = new SimpleJson(1, "账户不存在或者密码错误,或者未登录，请检查登录状态！");
        String json = JSON.toJSONString(result);
        //处理异常
        WebUtils.renderString(response, json);
    }
}
